﻿@using Smartstore.Web.Rendering.Menus
@using Smartstore.Collections
@using Smartstore.Core.Content.Menus
@using Microsoft.AspNetCore.Mvc.ViewFeatures

@model MenuModel

@{
    var root = Model.Root;
    if (root == null)
    {
        return;
    }

    var selectedNode = Model.SelectedNode;
}

<taro-view-core class="ca_container hydrated">
    <taro-view-core class="ca_title hydrated">
        @selectedNode.Value.Text
    </taro-view-core>
        @if (selectedNode.HasChildren)
        {
            <taro-view-core class="ca_content hydrated">
                @foreach (var node in selectedNode.Children)
                {
                    await CreateMenuItem2(node, selectedNode);
                }
            </taro-view-core>
        }
</taro-view-core>

@{
    async Task CreateMenuItem2(TreeNode<MenuItem> node, TreeNode<MenuItem> curNode)
    {
        var item = node.Value;
        var itemText = node.GetItemText(T);
        var itemUrl = item.GenerateUrl(this.ViewContext);
        
        <taro-view-core class="ca_content_content hydrated">
            <a href="@itemUrl">
                <taro-image-core class="ca_content_content_img hydrated">
                    @if (item.ImageId > 0)
                    {
                        <img class="taro-img__mode-aspectfit" src="@await Url.MediaAsync(item.ImageId, 80, null, false)">
                    }
                    else
                    {
                        <img class="taro-img__mode-aspectfit" src="~/images/default-image-alt.png" width="62px" height="62px">
                    }
                </taro-image-core>
                <taro-view-core class="ca_content_content_name hydrated">
                    @itemText
                </taro-view-core>
            </a>
        </taro-view-core>
    }
}